﻿using AuthCenter_HuangJingtao.Domain;
using AuthCenter_HuangJingtao.ErrorCode;
using AuthCenter_HuangJingtao.Infrastructure.Imterfaces;
using AuthCenter_HuangJingtao.Read.Api.Application.Command.ReversoaLL;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace AuthCenter_HuangJingtao.Read.Api.Application.CommandHandler.ReversoaLL
{
    public class DelReversoCommandHandler : IRequestHandler<DelReversoCommand, ApiResult<int>>
    {
        IBaseReponsitory<Reverso> Reverso;

        public DelReversoCommandHandler(IBaseReponsitory<Reverso> Reverso)
        {
            this.Reverso = Reverso;
        }

        public async Task<ApiResult<int>> Handle(DelReversoCommand request, CancellationToken cancellationToken)
        {
            var list = await Reverso.GetQuery().FirstOrDefaultAsync(c=>c.Reverso_Id==request.Id);
            list.Reverso_Isdel = true;

            await Reverso.UpdateAsync(list);
            return new ApiResult<int>
            {
                Code = ApiEnum.Success,
                Message = "添加成功",
                Data = 1
            };
        }
    }
}
